<?php

namespace Database\Seeders;

use App\Models\MoneyBook;
use App\Models\MoneyBookUser;
use App\Models\User;
use Illuminate\Database\Seeder;

class MoneyBookSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // 获取测试用户
        $user = User::where('email', 'test@example.com')->first();

        if ($user) {
            // 创建默认账本
            $book = MoneyBook::create([
                'user_id' => $user->id,
                'name' => '默认账本',
                'description' => '系统默认创建的账本',
                'is_default' => true,
            ]);

            // 将用户添加为账本管理员
            $book->users()->attach($user->id, ['role' => MoneyBookUser::ROLE_ADMIN]);
        }
    }
}
